package tech.eyao.hs60x.user.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import tech.eyao.hs60x.annotation.Admin;
import tech.eyao.hs60x.dto.BaseResult;
import tech.eyao.hs60x.model.domain.WatchConfigDO;
import tech.eyao.hs60x.service.WatchConfigService;
import tech.eyao.hs60x.utils.TokenUtils;

/**
 * 闹钟
 * 省电时段
 * 上课时间段
 * 关爱时间段
 * @author hejian
 * @date 2018年3月29日 上午10:10:30
 */
@RestController
@Api("闹钟|省电时段|上课时间段|关爱时间段 设置")
@RequestMapping("/watch")
public class WatchConfigController {
	
	private static final Logger logger = LoggerFactory.getLogger(WatchConfigController.class);
	@Autowired
	private WatchConfigService watchConfigService;
	
	@PostMapping(value="/setConfig.do")
    @ApiOperation(value = "设置", notes = "")
	public BaseResult setConfig(@ApiParam("操作code")int code, @ApiParam("内容 json") @RequestParam(value="context",defaultValue="")String context, @ApiParam("手表ID")long watchId) {
		try {
			return watchConfigService.setConfig(TokenUtils.getUserId(), code, context, watchId);
		} catch (Exception e) {
			logger.error("WatchConfigController setConfig error.", e);
		}
		return null;
	}
	
	@PostMapping(value = "getConfig.do")
    @ApiOperation(value = "获取属性",response = WatchConfigDO.class)
	public BaseResult getConfig(int code, long watchId) {
		try {
			return watchConfigService.getConfig(code, watchId);
		} catch (Exception e) {
			logger.error("WatchConfigController getConfig error.", e);
		}
		return null;
	}
	
	@PostMapping(value = "setStatus.do")
    @ApiOperation(value = "设置状态")
	@Admin
	public BaseResult setStatus(@ApiParam("ID")long id, @ApiParam("操作code")int code, @ApiParam("状态 1：在线 2：下线   不传默认为1") @RequestParam(value="status",defaultValue="1")int status) {
		try {
			return watchConfigService.setStatus(id, TokenUtils.getUserId(), code, status);
		} catch (Exception e) {
			logger.error("WatchConfigController setStatus error.", e);
		}
		return null;
	}
}
